package com.example.demo.controller;/**
 * ClassName: RepairController
 * Package: com.example.demo.controller
 * Description:
 *
 * @Author 理理
 * @Create 2024/11/16 19:19
 * @Version 1.0
 */

import com.example.demo.entity.Repair;
import com.example.demo.entity.Subscribe;
import com.example.demo.entity.TimeQuantum;
import com.example.demo.mapper.RepairMapper;
import com.example.demo.mapper.SubscribeMapper;
import com.example.demo.mapper.TimeQuantumMapper;
import com.example.demo.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 *@title: RepairController
 *@Author: Tangerine
 *@Date: 2024/11/16 19:19
 *@version 1.0
 */
@RestController
@RequestMapping("/repair")
public class RepairController {
    @Autowired
    private RepairMapper repairMapper;
    @Autowired
    private RepairService repairService;
    @GetMapping("/")
    public List<Repair> index(){
        return repairMapper.findAll();
    }

    //分页查询,返回总条数及当前需要页的数据
    @GetMapping("/page")
    public Map<String,Object> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        pageNum = (pageNum-1)*pageSize;
        List<Repair> data = repairService.selectPage(pageNum,pageSize);
        Integer total = repairMapper.selectTotal();
        Map<String,Object> res = new HashMap<>();
        res.put("data",data);
        res.put("total",total);
        return res;
    }
    //增加或修改一个维修数据 （用户和管理员，前端设置不同表单）
    @PostMapping
    public Integer save(@RequestBody Repair repair){
        return repairService.save(repair);
    }

    //删除数据
    @DeleteMapping("/{id}")
    public Integer deleteById(@PathVariable Integer id){
        return  repairMapper.deleteById(id);
    }

    //查询全部历史预约
    @GetMapping("/history")
    public List<Repair> findHistory(@RequestParam String studentNumber){
        return repairService.findHistory(studentNumber);
    }
    //分页查询历史预约
    @GetMapping("/hPage")
    public List<Repair> findHistoryPage(@RequestParam String studentNumber,@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        pageNum = (pageNum-1)*pageSize;
        return repairService.findHistoryPage(studentNumber,pageNum,pageSize);
    }
}
